package com.atguigu.gmall.juc.atomic;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * @author 陈昆昆
 * @version 1.0
 * @date 2020/6/2 18:11
 */
public class CyclicBarril {
    public static void main(String[] args) {
        CyclicBarrier cyclicBarrier = new CyclicBarrier(7,()->{
            System.out.println("龙珠收集到齐");
        });
        for (int i = 1; i <=7 ; i++) {
            new Thread(()->{
                System.out.println(Thread.currentThread().getName()+"课龙珠收集");
                try { cyclicBarrier.await(); } catch (InterruptedException e) { e.printStackTrace(); } catch (BrokenBarrierException e) { e.printStackTrace(); }
            },String.valueOf(i)).start();
        }
    }
}
